package com.wordpress.thenonsensetechlogs.weathermonitor.station;

import java.util.ArrayList;
import java.util.List;

public class WeatherMonitoringStation implements Observable {
	
	private String temperature;
	private String pressure;
	private String humidity;
	
	List<Observer> observersList = null;
	
	

	public String getTemperature() {
		return temperature;
	}

	public String getPressure() {
		return pressure;
	}

	public String getHumidity() {
		return humidity;
	}

	public List<Observer> getObserversList() {
		return observersList;
	}

	public WeatherMonitoringStation() {

		observersList = new ArrayList<Observer>();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.wordpress.thenonsensetechlogs.weathermonitor.station.Observable#
	 * deRegisterObserver
	 * (com.wordpress.thenonsensetechlogs.weathermonitor.station.Observer)
	 */
	public boolean deRegisterObserver(Observer observer) {

		if (observersList.contains(observer)) {

			observersList.remove(observer);
			System.out.println("De Registered observer");
			return true;
		} else {

			System.out.println("List does not contain this Observer");
			return false;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.wordpress.thenonsensetechlogs.weathermonitor.station.Observable#
	 * notifyObservers()
	 */
	public void notifyObservers() {

		for (Observer observer : observersList) {

			observer.update(this);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @seecom.wordpress.thenonsensetechlogs.weathermonitor.station.Observable#
	 * registerObserver
	 * (com.wordpress.thenonsensetechlogs.weathermonitor.station.Observer)
	 */
	public boolean registerObserver(Observer observer) {

		if (!observersList.contains(observer)) {
			observersList.add(observer);
			System.out.println("Registered Observer");
			return true;
		} else {

			System.out.println("Already in the list");
			return false;
		}
	}
	
	public void measurementsChanged() {
		
		temperature = "30 degree celsius";
		pressure = "100 ps";
		humidity = "30 something";
		
		notifyObservers();
	}
	
}
